import util from '@/libs/util';
import getDate from '@/util/getDate.js';
import Cookies from 'js-cookie';

export default {
    name: 'exportable-table',
    data () {
        return {
            columns: [{
                title: '序号',
                key: 'rownum',
                align: 'center',
                width: 60,
                render: (h, params) => {
                    return h('div', {}, ((this.pageIndex - 1) * this.pageSize + params.index + 1));
                }
            }, {
                title: '教师姓名',
                key: 'mainTeacherName'
            }, {
                title: '班级',
                key: 'className'
            }, {
                title: '签到时间',
                key: 'attendanceTime',
                render: (h, params) => {
                return h('div', {}, getDate.getDate(params.row.attendanceTime, 'time'))
                }
            },  {title: '操作',
                key: 'action',
                width: 200,
                align: 'center',
                render: (h, params) => {
                    return h('div', [
                        h('Button', {
                            props: {
                                type: 'error',
                                size: 'small'
                            },
                            on: {
                                click: () => {
                                    this.delete(params.row.id);
                                }
                            }
                        }, '删除')
                    ]);
                }
            }],
            data: [],
            formData: {},
            query: {
                name: ''
            },
            total: 0,
            pageIndex: 1,
            pageSize: 10,
            orgTree: [],
            majorTree: [],
            ids: [],
            baseuser: JSON.parse(Cookies.get('baseUser')),
            editModal: false,
            isRead: false,

        };
    },
    mounted () {
        this.into();
    },
    methods: {
        into () {
            util.ajax.post('/busine/tescher/info/list', util.toFormData(
                {id: 0}
            )).then(res => {
                this.teacherList = res.data.data.list;
        });
            this.loadList();
        },
        loadList () {
            util.ajax.post('/busine/teacher/listAttendance', util.toFormData({
                page: this.pageIndex,
                size: this.pageSize,
                name: this.query.name ? this.query.name : ''
            })).then(res => {
                this.data = res.data.data.list;
                this.total = res.data.data.total;
            });
        },
        refresh () {
            this.query = {
                name: ''
            };
            this.into();
        },
        delete (id) {
            this.$Modal.confirm({
                title: '提示',
                content: '<p>确定删除？</p>',
                onOk: () => {
                    util.ajax.post('/busine/teacher/delete', util.toFormData({
                        id: id
                    })).then(res => {
                        if (res.data.message === 'SUCCESS') {
                            this.$Message.success('删除成功！');
                            this.loadList();
                        }
                    });
                }
            });
        }
    }
}